//
//  IHLabel.m
//  MyProject
//
//  Created by Pei on 16/6/21.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "IHLabel.h"
#import "UIView+Additions.h"
#import "UILabel+Utilities.h"

@implementation IHLabel

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self setBackgroundColor:[UIColor clearColor]];
    }
    return self;
}

+ (IHLabel *)commonLabel:(NSString *)text font:(UIFont *)font {
    IHLabel *label = [[IHLabel alloc] init];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setFont:font];
    [label setText:text];
    [label sizeToFit];
    
    return label;
}

+ (IHLabel *)commonLabel:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor {
    IHLabel *label = [IHLabel commonLabel:text font:font];
    [label setTextColor:textColor];
    
    return label;
}

+ (IHLabel *)whiteLabel:(NSString *)text font:(UIFont *)font {
    IHLabel *label = [IHLabel commonLabel:text font:font];
    [label setTextColor:[UIColor whiteColor]];
    
    return label;
}

- (void)autoAdjustHeight {
    [self setNumberOfLines:0];
    self.height = [self.text boundingRectWithSize:CGSizeMake(self.width, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:self.font} context:nil].size.height;
}
/*
-(void)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width lineSpacing:(float)spacingF
{
    
    [self setNumberOfLines:0];
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = spacingF;
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f};
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, kDeviceHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    //return size.height;
    self.height = size.height;
}
*/
- (void)autoAdjustWidth {
    [self setNumberOfLines:1];
    self.width = [self.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, self.height) options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:self.font} context:nil].size.width;
}

@end
